package cn.stronglink.assetmanage.index.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

/**
 * @author zww
 * 2018 2018/6/10 13:26
 */
public abstract class BaseFragment<V,P extends BasePresenter<V>> extends Fragment {
    protected P mPresenter;
    @Override
    public void onCreate (@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(mPresenter!=null) {
            mPresenter = createPresenter();
            mPresenter.attachView((V) this);
        }
    }

    @Override
    public void onStart () {
        super.onStart();
        if(mPresenter!=null) {
            mPresenter.onStart();
        }
    }

    @Override
    public void onStop () {
        super.onStop();
        if(mPresenter!=null) {
            mPresenter.onStop();
        }
    }

    @Override
    public void onDestroy () {
        super.onDestroy();
        if(mPresenter!=null) {
            mPresenter.detachView();
        }
    }

    protected abstract P createPresenter();
}
